function [n,v]=voice_detector(b,a,x)

%coefficients for low pass filtering as part of peak detection 

%a1 = [ 1.0000   -1.9956    0.9956];

a1 = [1.0000   -1.9779    0.9783];
b1 = [1.9559e-04  -4.4528e-06  1.9559e-04];
%apply bandpass filter
cc = iir_filt_1(b, -a(2:length(a)), x, 0);

%perform peak detection on filtered signal
dd = iir_filt_1(b1,-a1(2:length(a1)),cc,1);




%perform peak detection on overall signal
ff = iir_filt_1(b1,-a1(2:length(a1)),x,1);



%compare the two peak detected signals...output noise(n) or voice(v)

% setup input

for i=1:length(dd); 
     if dd(i) > 0.002e-04 & ff < 0.05e-04
         v(i) = 1;
         n(i) =0;
     elseif dd(i)<0.002e-04 & ff > 0.05e-04
         n(i) = 1;
         v(i) = 0;
     else
         n(i) =0;
         v(i) = 0;
     end  
 
end

for i=1:length(dd);
    if dd(i)> 0.002 & ff(i) <0.05
        v(i) =1;
    else
        v(i) = 0;
    end
end
